package com.kang.controller;

import com.github.pagehelper.PageInfo;
import com.kang.Vo.NoticeVo;
import com.kang.commons.Result;
import com.kang.bean.Notice;
import com.kang.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @program: photo_fawu
 * @description:
 * @author: K.faWu
 * @create: 2021-11-19 14:22
 **/
@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    /**
     * 获取公告列表
     */
    @PostMapping("/getList")
    public Result<?> getList(@RequestBody NoticeVo noticeVo, Pageable page){
        PageInfo<NoticeVo> list = noticeService.getList(noticeVo, page);
        return Result.success(list);
    }

    /**
     * 获取最新的公告
     */
    @GetMapping
    public Result<?> getNewNotice(){

        List<NoticeVo> noticeVos = noticeService.getNew();
        return Result.success(noticeVos);
    }

    /**
     * 发布公告
     */
    @PostMapping
    public Result<?> addNotice(@RequestBody Notice notice, HttpServletRequest request){
        noticeService.addNotice(notice, request);
        return Result.success();
    }
}
